#ifndef V_TESS_H
#define V_TESS_H
#include <vector>
#include <map>
#include <set>
#include "Terrain.h"
#include "VoronoiDiagramGenerator.h"
#include "Graph.h"
#include <queue>

#define LineSeg std::pair<D3DXVECTOR2,D3DXVECTOR2>
#define VecLineSeg std::vector<LineSeg>

struct D3DV2Less : public std::binary_function<D3DXVECTOR2,D3DXVECTOR2,bool>
{
	bool operator()(const D3DXVECTOR2& a, const D3DXVECTOR2& b) const
	{
		if(a.x<b.x)
		{return true;}
		if(a.x>b.x)
		{return false;}
		if(a.y<b.y)
		{return true;}
		return false;
	}
};

struct GNLess : public std::binary_function<GraphNode,GraphNode,bool>
{
	bool operator()(const GraphNode& a, const GraphNode& b) const
	{
		if(a.GetPos().x<b.GetPos().x)
		{return true;}
		if(a.GetPos().x>b.GetPos().x)
		{return false;}
		if(a.GetPos().y<b.GetPos().y)
		{return true;}
		return false;
	}
};
#define D3DV2SET std::set<D3DXVECTOR2,D3DV2Less> 
#define NODEMAP std::map<D3DXVECTOR2,std::queue<D3DXVECTOR2>,D3DV2Less>

class VTesselation
{
public:
	
	void CreateRandomPoints(Terrain* t);
	void Divide();
	std::vector<D3DXVECTOR2> GetPoints(){return m_vPoints;}
	VecLineSeg GetEdges(){return m_vEdges;}
	D3DV2SET GetNodes(){return m_setNodes;}
	NODEMAP GetNodeMap(){return m_mapNodeLinks;}
	Graph* GetGraph(){return &m_Graph;}
private:
	std::vector<D3DXVECTOR2> m_vPoints;
	D3DV2SET m_setNodes;
	VecLineSeg m_vEdges;
	NODEMAP m_mapNodeLinks;
	VoronoiDiagramGenerator m_Generator;
	float* m_Xvals;
	float* m_Yvals;
	int m_numOfPoints;
	float m_minX;
	float m_minY;
	float m_maxX;
	float m_maxY;
	Graph m_Graph;
};
#endif